; 参考的 https://blog.csdn.net/weixin_39925413/article/details/111384536?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0.no_search_link&spm=1001.2101.3001.4242.1
(define zero 
    (lambda (f)
        (lambda (x) x)
    )
)
(define (add-1 n)
    (lambda (f)
        (lambda (x)
            (f ((n f) x))
        )   
    )
)
; (display (add-1 zero))
; ->(lambda (f) (lambda (x) (f ((n f) x), zero)))
; ->(lambda (f) (lambda (x) (f ((zero f) x))))
; ->(lambda (f) (lambda (x) (f ((lambda(y) y) x))))
; ->(lambda (f) (lambda (x) (f x)))

(define one
    (lambda (f) (lambda (x) (f x)))
)

(define two
    (lambda (f) (lambda (x) (f (f x))))
)

(define (add-church m n)
    (lambda (f) 
        (lambda (x) ((m f) ((n f) x)))
    )
)
;test
(define (inc x) (+ 1 x))
(define (square x) (* x x))

(display ((zero inc) 1))
(newline)
(display ((one inc) 1))
(newline)
(display ((two inc) 1))
(newline)
(display ((zero square) 2))
(newline)
(display ((one square) 2))
(newline)
(display ((two square) 2))
(display (((add-church one two) square) 2))

(exit)